home *** CD-ROM | disk | FTP | other *** search
/ Creating Your Own America Online Web Pages / Creating Your Own America Online Web Pages.iso / TOOLS / TEX2RTF / SOURCES.ZIP / SRC / HTMLUTIL.CC < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-18  |  36.2 KB  |  1,748 lines

  1. /*
  2.  * htmlutil.cc
  3.  *
  4.  * Utility functions for helping convert Latex files
  5.  * into HTML files.
  6.  * files.
  7.  *
  8.  * Julian Smart September 1993
  9.  *
  10.  */
  11.  
  12. #include <wx.h>
  13. #include "tex2any.h"
  14. #include "tex2rtf.h"
  15.  
  16. char *ChaptersName = NULL;
  17. char *SectionsName = NULL;
  18. char *SubsectionsName = NULL;
  19. char *SubsubsectionsName = NULL;
  20. char *TitlepageName = NULL;
  21. char *lastFileName = NULL;
  22. char *lastTopic = NULL;
  23.  
  24. static TexChunk *descriptionItemArg = NULL;
  25. static TexChunk *helpRefFilename = NULL;
  26. static TexChunk *helpRefText = NULL;
  27. static int indentLevel = 0;
  28. static int citeCount = 1;
  29. extern FILE *Contents;
  30. FILE *Titlepage = NULL;
  31. int fileId = 0;
  32.  
  33. // Are we in verbatim mode? If so, format differently.
  34. static Bool inVerbatim = FALSE;
  35.  
  36. // This is defined in the Tex2Any library.
  37. extern char *BigBuffer;
  38.  
  39. class HyperReference: public wxObject
  40. {
  41.  public:
  42.   char *refName;
  43.   char *refFile;
  44.   HyperReference(char *name, char *file)
  45.   {
  46.     if (name) refName = copystring(name);
  47.     if (file) refFile = copystring(file);
  48.   }
  49. };
  50.  
  51. class TexNextPage: public wxObject
  52. {
  53.  public:
  54.   char *label;
  55.   char *filename;
  56.   TexNextPage(char *theLabel, char *theFile)
  57.   {
  58.     label = copystring(theLabel);
  59.     filename = copystring(theFile);
  60.   }
  61.   ~TexNextPage(void)
  62.   {
  63.     delete[] label;
  64.     delete[] filename;
  65.   }
  66. };
  67.  
  68. wxHashTable TexNextPages(wxKEY_STRING);
  69.  
  70. static char *CurrentChapterName = NULL;
  71. static char *CurrentChapterFile = NULL;
  72. static char *CurrentSectionName = NULL;
  73. static char *CurrentSectionFile = NULL;
  74. static char *CurrentSubsectionName = NULL;
  75. static char *CurrentSubsectionFile = NULL;
  76. static char *CurrentSubsubsectionName = NULL;
  77. static char *CurrentSubsubsectionFile = NULL;
  78.  
  79. void SetCurrentChapterName(char *s, char *file)
  80. {
  81.   if (CurrentChapterName) delete[] CurrentChapterName;
  82.   CurrentChapterName = copystring(s);
  83.   if (CurrentChapterFile) delete[] CurrentChapterFile;
  84.   CurrentChapterFile = copystring(file);
  85. }
  86. void SetCurrentSectionName(char *s, char *file)
  87. {
  88.   if (CurrentSectionName) delete[] CurrentSectionName;
  89.   CurrentSectionName = copystring(s);
  90.   if (CurrentSectionFile) delete[] CurrentSectionFile;
  91.   CurrentSectionFile = copystring(file);
  92. }
  93. void SetCurrentSubsectionName(char *s, char *file)
  94. {
  95.   if (CurrentSubsectionName) delete[] CurrentSubsectionName;
  96.   CurrentSubsectionName = copystring(s);
  97.   if (CurrentSubsectionFile) delete[] CurrentSubsectionFile;
  98.   CurrentSubsectionFile = copystring(file);
  99. }
  100. void SetCurrentSubsubsectionName(char *s, char *file)
  101. {
  102.   if (CurrentSubsubsectionName) delete[] CurrentSubsubsectionName;
  103.   CurrentSubsubsectionName = copystring(s);
  104.   if (CurrentSubsubsectionFile) delete[] CurrentSubsubsectionFile;
  105.   CurrentSubsubsectionFile = copystring(file);
  106. }
  107.  
  108. /*
  109.  * Close former filedescriptor and reopen using another filename.
  110.  *
  111.  */
  112.  
  113. void ReopenFile(FILE **fd, char **fileName)
  114. {
  115.   if (*fd)
  116.   {
  117.     fclose(*fd);
  118.   }
  119.   fileId ++;
  120.   char buf[200];
  121.   sprintf(buf, "%s%d.html", FileRoot, fileId);
  122.   if (*fileName) delete[] *fileName;
  123.   *fileName = copystring(FileNameFromPath(buf));
  124.   *fd = fopen(buf, "w");
  125. }
  126.  
  127. /*
  128.  * Given a TexChunk with a string value, scans through the string
  129.  * converting Latex-isms into HTML-isms, such as 2 newlines -> <P>.
  130.  *
  131.  */
  132.  
  133. void ProcessText2HTML(TexChunk *chunk)
  134. {
  135.   Bool changed = FALSE;
  136.   int ptr = 0;
  137.   int i = 0;
  138.   char ch = 1;
  139.   int len = strlen(chunk->value);
  140.   while (ch != 0)
  141.   {
  142.     ch = chunk->value[i];
  143.  
  144.     // 2 newlines means \par
  145.     if (!inVerbatim && chunk->value[i] == 10 && ((len > i+1 && chunk->value[i+1] == 10) ||
  146.                         ((len > i+1 && chunk->value[i+1] == 13) &&
  147.                         (len > i+2 && chunk->value[i+2] == 10))))
  148.     {
  149.       BigBuffer[ptr] = 0; strcat(BigBuffer, "<P>\n\n"); ptr += 5;
  150.       i += 2;
  151.       changed = TRUE;
  152.     }
  153.     else if (!inVerbatim && ch == '`' && (len >= i+1 && chunk->value[i+1] == '`'))
  154.     {
  155.       BigBuffer[ptr] = '"'; ptr ++;
  156.       i += 2;
  157.       changed = TRUE;
  158.     }
  159.     else if (!inVerbatim && ch == '`') // Change ` to '
  160.     {
  161.       BigBuffer[ptr] = 39; ptr ++;
  162.       i += 1;
  163.       changed = TRUE;
  164.     }
  165.     else if (!inVerbatim && ch == '<') // Change < to <
  166.     {
  167.       BigBuffer[ptr] = 0;
  168.       strcat(BigBuffer, "<");
  169.       ptr += 4;
  170.       i += 1;
  171.       changed = TRUE;
  172.     }
  173.     else if (!inVerbatim && ch == '>') // Change > to >
  174.     {
  175.       BigBuffer[ptr] = 0;
  176.       strcat(BigBuffer, ">");
  177.       ptr += 4;
  178.       i += 1;
  179.       changed = TRUE;
  180.     }
  181.     else
  182.     {
  183.       BigBuffer[ptr] = ch;
  184.       i ++;
  185.       ptr ++;
  186.     }
  187.   }
  188.   BigBuffer[ptr] = 0;
  189.  
  190.   if (changed)
  191.   {
  192.     delete chunk->value;
  193.     chunk->value = copystring(BigBuffer);
  194.   }
  195. }
  196.  
  197. /*
  198.  * Scan through all chunks starting from the given one,
  199.  * calling ProcessText2HTML to convert Latex-isms to RTF-isms.
  200.  * This should be called after Tex2Any has parsed the file,
  201.  * and before TraverseDocument is called.
  202.  *
  203.  */
  204.  
  205. void Text2HTML(TexChunk *chunk)
  206. {
  207.   Tex2RTFYield();
  208.   if (stopRunning) return;
  209.  
  210.   switch (chunk->type)
  211.   {
  212.     case CHUNK_TYPE_MACRO:
  213.     {
  214.       TexMacroDef *def = chunk->def;
  215.  
  216.       if (def && def->ignore)
  217.         return;
  218.  
  219.       if (def && (def->macroId == ltVERBATIM))
  220.         inVerbatim = TRUE;
  221.  
  222.       wxNode *node = chunk->children.First();
  223.       while (node)
  224.       {
  225.         TexChunk *child_chunk = (TexChunk *)node->Data();
  226.         Text2HTML(child_chunk);
  227.         node = node->Next();
  228.       }
  229.  
  230.       if (def && (def->macroId == ltVERBATIM))
  231.         inVerbatim = FALSE;
  232.  
  233.       break;
  234.     }
  235.     case CHUNK_TYPE_ARG:
  236.     {
  237.       wxNode *node = chunk->children.First();
  238.       while (node)
  239.       {
  240.         TexChunk *child_chunk = (TexChunk *)node->Data();
  241.         Text2HTML(child_chunk);
  242.         node = node->Next();
  243.       }
  244.  
  245.       break;
  246.     }
  247.     case CHUNK_TYPE_STRING:
  248.     {
  249.       if (chunk->value)
  250.         ProcessText2HTML(chunk);
  251.       break;
  252.     }
  253.   }
  254. }
  255.  
  256. /*
  257.  * Add appropriate browse buttons to this page.
  258.  *
  259.  */
  260.  
  261. void AddBrowseButtons(char *upLabel, char *upFilename,
  262.   char *previousLabel, char *previousFilename,
  263.   char *thisLabel, char *thisFilename)
  264. {
  265.   if (htmlBrowseButtons == HTML_BUTTONS_NONE)
  266.     return;
  267.  
  268.   char *contentsReference = NULL;
  269.   if (htmlBrowseButtons == HTML_BUTTONS_TEXT)
  270.     contentsReference = ContentsNameString;
  271.   else
  272.     contentsReference = "<img align=top src=\"contents.gif\">";
  273.  
  274.   char *upReference = NULL;
  275.   if (htmlBrowseButtons == HTML_BUTTONS_TEXT)
  276.     upReference = UpNameString;
  277.   else
  278.     upReference = "<img align=top src=\"up.gif\">";
  279.  
  280.   char *backReference = NULL;
  281.   if (htmlBrowseButtons == HTML_BUTTONS_TEXT)
  282.     backReference = "<<";
  283.   else
  284.     backReference = "<img align=top src=\"back.gif\">";
  285.  
  286.   char *forwardReference = NULL;
  287.   if (htmlBrowseButtons == HTML_BUTTONS_TEXT)
  288.     forwardReference = ">>";
  289.   else
  290.     forwardReference = "<img align=top src=\"forward.gif\">";
  291.   
  292.   char buf[200];
  293.  
  294.   /*
  295.    * Contents button
  296.    *
  297.    */
  298.  
  299.   sprintf(buf, "\n<A HREF=\"%s_contents.html\">%s</A> ", FileNameFromPath(FileRoot), contentsReference);
  300.   TexOutput(buf);
  301.  
  302.   /*
  303.    * Up button
  304.    *
  305.    */
  306.  
  307.   if (upLabel && upFilename)
  308.   {
  309.     if (strlen(upLabel) > 0)
  310.       sprintf(buf, "<A HREF=\"%s#%s\">%s</A> ", upFilename, upLabel, upReference);
  311.     else
  312.       sprintf(buf, "<A HREF=\"%s\">%s</A> ", upFilename, upReference);
  313.     TexOutput(buf);
  314.   }
  315.  
  316.   /*
  317.    * << button
  318.    *
  319.    */
  320.  
  321.   if (previousLabel && previousFilename)
  322.   {
  323.     sprintf(buf, "<A HREF=\"%s#%s\">%s</A> ", previousFilename, previousLabel, backReference);
  324.     TexOutput(buf);
  325.   }
  326.  
  327.   char *nextLabel = NULL;
  328.   char *nextFilename = NULL;
  329.  
  330.   // Get the next page, and record the previous page's 'next' page
  331.   // (i.e. this page)
  332.   TexNextPage *nextPage = (TexNextPage *)TexNextPages.Get(thisLabel);
  333.   if (nextPage)
  334.   {
  335.     nextLabel = nextPage->label;
  336.     nextFilename = nextPage->filename;
  337.   }
  338.   if (previousLabel && previousFilename)
  339.   {
  340.     TexNextPage *oldNextPage = (TexNextPage *)TexNextPages.Get(previousLabel);
  341.     if (oldNextPage)
  342.     {
  343.       delete oldNextPage;
  344.       TexNextPages.Delete(previousLabel);
  345.     }
  346.     TexNextPage *newNextPage = new TexNextPage(thisLabel, thisFilename);
  347.     TexNextPages.Put(previousLabel, newNextPage);
  348.   }
  349.  
  350.   /*
  351.    * >> button
  352.    *
  353.    */
  354.  
  355.   if (nextLabel && nextFilename)
  356.   {
  357.     sprintf(buf, "<A HREF=\"%s#%s\">%s</A> ", nextFilename, nextLabel, forwardReference);
  358.     TexOutput(buf);
  359.   }
  360.  
  361.   /*
  362.    * Horizontal rule to finish it off nicely, and a break to add space
  363.    * before the following title.
  364.    *
  365.    */
  366.   TexOutput("<HR><BR>\n");
  367.  
  368.   // Update last topic/filename
  369.   if (lastFileName)
  370.     delete[] lastFileName;
  371.   lastFileName = copystring(thisFilename);
  372.   if (lastTopic)
  373.     delete[] lastTopic;
  374.   lastTopic = copystring(thisLabel);
  375. }
  376.  
  377. // Called on start/end of macro examination
  378. void HTMLOnMacro(int macroId, int no_args, Bool start)
  379. {
  380.   switch (macroId)
  381.   {
  382.   case ltCHAPTER:
  383.   case ltCHAPTERSTAR:
  384.   case ltCHAPTERHEADING:
  385.   {
  386.     if (!start)
  387.     {
  388.       sectionNo = 0;
  389.       figureNo = 0;
  390.       subsectionNo = 0;
  391.       subsubsectionNo = 0;
  392.       if (macroId != ltCHAPTERSTAR)
  393.         chapterNo ++;
  394.  
  395.       SetCurrentOutput(NULL);
  396.       startedSections = TRUE;
  397.  
  398.       char *topicName = FindTopicName(GetNextChunk());
  399.       ReopenFile(&Chapters, &ChaptersName);
  400.       AddTexRef(topicName, ChaptersName, ChapterNameString);
  401.  
  402.       SetCurrentChapterName(topicName, ChaptersName);
  403.  
  404.       SetCurrentOutput(Chapters);
  405.       fprintf(Chapters, "<A NAME=\"%s\"><H2>", topicName);
  406.  
  407.       char titleBuf[100];
  408.       sprintf(titleBuf, "%s_contents.html", FileNameFromPath(FileRoot));
  409.       AddBrowseButtons("", titleBuf, // Up
  410.                        lastTopic, lastFileName,  // Last topic
  411.                        topicName, ChaptersName); // This topic
  412.  
  413.       TexOutput("<title>");
  414.       OutputCurrentSection(); // Repeat section header
  415.       TexOutput("</title>\n");
  416.  
  417.       SetCurrentOutputs(Contents, Chapters);
  418.       fprintf(Contents, "\n<LI><A HREF=\"%s#%s\">", ChaptersName, topicName);
  419.  
  420.       OutputCurrentSection();
  421.       fprintf(Contents, "</A>\n");
  422.       fprintf(Chapters, "</H2></A>\n");
  423.  
  424.       SetCurrentOutput(Chapters);
  425.     }
  426.     break;
  427.   }
  428.   case ltSECTION:
  429.   case ltSECTIONSTAR:
  430.   case ltSECTIONHEADING:
  431.   case ltGLOSS:
  432.   {
  433.     if (!start)
  434.     {
  435.       subsectionNo = 0;
  436.       subsubsectionNo = 0;
  437.  
  438.       if (macroId != ltSECTIONSTAR)
  439.         sectionNo ++;
  440.         
  441.       SetCurrentOutput(NULL);
  442.       startedSections = TRUE;
  443.  
  444.       char *topicName = FindTopicName(GetNextChunk());
  445.       ReopenFile(&Sections, &SectionsName);
  446.       AddTexRef(topicName, SectionsName, SectionNameString);
  447.  
  448.       SetCurrentSectionName(topicName, SectionsName);
  449.  
  450.       SetCurrentOutput(Sections);
  451.       fprintf(Sections, "<A NAME=\"%s\"><H2>", topicName);
  452.  
  453.       AddBrowseButtons(CurrentChapterName, CurrentChapterFile, // Up
  454.                        lastTopic, lastFileName,  // Last topic
  455.                        topicName, SectionsName); // This topic
  456.  
  457.       TexOutput("<title>");
  458.       OutputCurrentSection();
  459.       TexOutput("</title>\n");
  460.  
  461.       FILE *jumpFrom = ((DocumentStyle == LATEX_ARTICLE) ? Contents : Chapters);
  462.  
  463.       SetCurrentOutputs(jumpFrom, Sections);
  464.       if (DocumentStyle == LATEX_ARTICLE)
  465.         fprintf(jumpFrom, "\n<LI><A HREF=\"%s#%s\">", SectionsName, topicName);
  466.       else
  467.         fprintf(jumpFrom, "\n<A HREF=\"%s#%s\"><B>", SectionsName, topicName);
  468.  
  469.       OutputCurrentSection();
  470.  
  471.       if (DocumentStyle == LATEX_ARTICLE)
  472.         fprintf(jumpFrom, "</A>\n");
  473.       else
  474.         fprintf(jumpFrom, "</B></A><BR>\n");
  475.       fprintf(Sections, "</H2></A>\n");
  476.  
  477.       SetCurrentOutput(Sections);
  478.     }
  479.     break;
  480.   }
  481.   case ltSUBSECTION:
  482.   case ltSUBSECTIONSTAR:
  483.   case ltMEMBERSECTION:
  484.   case ltFUNCTIONSECTION:
  485.   {
  486.     if (!start)
  487.     {
  488.       subsubsectionNo = 0;
  489.  
  490.       if (macroId != ltSUBSECTIONSTAR)
  491.         subsectionNo ++;
  492.  
  493.       SetCurrentOutput(NULL);
  494.       startedSections = TRUE;
  495.  
  496.       char *topicName = FindTopicName(GetNextChunk());
  497.       ReopenFile(&Subsections, &SubsectionsName);
  498.       AddTexRef(topicName, SubsectionsName, SubsectionNameString);
  499.  
  500.       SetCurrentSubsectionName(topicName, SubsectionsName);
  501.  
  502.       SetCurrentOutput(Subsections);
  503.       fprintf(Subsections, "<A NAME=\"%s\"><H2>", topicName);
  504.  
  505.       AddBrowseButtons(CurrentSectionName, CurrentSectionFile, // Up
  506.                        lastTopic, lastFileName,  // Last topic
  507.                        topicName, SubsectionsName); // This topic
  508.  
  509.       TexOutput("<title>");
  510.       OutputCurrentSection();
  511.       TexOutput("</title>\n");
  512.  
  513.       SetCurrentOutputs(Sections, Subsections);
  514.       fprintf(Sections, "\n<A HREF=\"%s#%s\"><B>", SubsectionsName, topicName);
  515.       OutputCurrentSection();
  516.       fprintf(Sections, "</B></A><BR>\n");
  517.       fprintf(Subsections, "</H2></A>\n");
  518.  
  519.       SetCurrentOutput(Subsections);
  520.     }
  521.     break;
  522.   }
  523.   case ltSUBSUBSECTION:
  524.   case ltSUBSUBSECTIONSTAR:
  525.   {
  526.     if (!start)
  527.     {
  528.       if (macroId != ltSUBSUBSECTIONSTAR)
  529.         subsubsectionNo ++;
  530.  
  531.       SetCurrentOutput(NULL);
  532.       startedSections = TRUE;
  533.  
  534.       char *topicName = FindTopicName(GetNextChunk());
  535.       ReopenFile(&Subsubsections, &SubsubsectionsName);
  536.       AddTexRef(topicName, SubsubsectionsName, SubsubsectionNameString);
  537.  
  538.       SetCurrentSubsubsectionName(topicName, SubsubsectionsName);
  539.  
  540.       SetCurrentOutput(Subsubsections);
  541.       fprintf(Subsubsections, "<A NAME=\"%s\"><H3>", topicName);
  542.  
  543.       AddBrowseButtons(CurrentSubsectionName, CurrentSubsectionFile, // Up
  544.                        lastTopic, lastFileName,  // Last topic
  545.                        topicName, SubsubsectionsName); // This topic
  546.  
  547.       TexOutput("<title>");
  548.       OutputCurrentSection();
  549.       TexOutput("</title>\n");
  550.  
  551.       SetCurrentOutputs(Subsections, Subsubsections);
  552.       fprintf(Subsections, "\n<A HREF=\"%s#%s\"><B>", SubsubsectionsName, topicName);
  553.       OutputCurrentSection();
  554.       fprintf(Subsections, "</B></A><BR>\n");
  555.       fprintf(Subsubsections, "</H3></A>\n");
  556.  
  557.       SetCurrentOutput(Subsubsections);
  558.     }
  559.     break;
  560.   }
  561.   case ltFUNC:
  562.   case ltPFUNC:
  563.   {
  564.     SetCurrentOutput(Subsections);
  565.     if (start)
  566.     {
  567.     }
  568.     else
  569.     {
  570.     }
  571.     break;
  572.   }
  573.   case ltCLIPSFUNC:
  574.   {
  575.     SetCurrentOutput(Subsections);
  576.     if (start)
  577.     {
  578.     }
  579.     else
  580.     {
  581.     }
  582.     break;
  583.   }
  584.   case ltMEMBER:
  585.   {
  586.     SetCurrentOutput(Subsections);
  587.     if (start)
  588.     {
  589.     }
  590.     else
  591.     {
  592.     }
  593.     break;
  594.   }
  595.   case ltVOID:
  596.     if (start)
  597.       TexOutput("<B>void</B>");
  598.     break;
  599.   case ltHARDY:
  600.     if (start)
  601.       TexOutput("HARDY");
  602.     break;
  603.   case ltWXCLIPS:
  604.     if (start)
  605.       TexOutput("wxCLIPS");
  606.     break;
  607.   case ltAMPERSAND:
  608.     if (start)
  609.       TexOutput("&");
  610.     break;
  611.   case ltBACKSLASHCHAR:
  612.     if (start)
  613.       TexOutput("<BR>\n");
  614.     break;
  615.   case ltRTFSP:  // Explicit space, RTF only
  616.     break;
  617.   case ltITEMIZE:
  618.   case ltENUMERATE:
  619.   case ltDESCRIPTION:
  620.   case ltTWOCOLLIST:
  621.   {
  622.     if (start)
  623.     {
  624.       indentLevel ++;
  625.  
  626.       int listType;
  627.       if (macroId == ltENUMERATE)
  628.         listType = LATEX_ENUMERATE;
  629.       else if (macroId == ltITEMIZE)
  630.         listType = LATEX_ITEMIZE;
  631.       else
  632.         listType = LATEX_DESCRIPTION;
  633.  
  634.       itemizeStack.Insert(new ItemizeStruc(listType));
  635.       switch (listType)
  636.       {
  637.         case LATEX_ITEMIZE:
  638.           TexOutput("<UL>\n");
  639.           break;
  640.         case LATEX_ENUMERATE:
  641.           TexOutput("<OL>\n");
  642.           break;
  643.         case LATEX_DESCRIPTION:
  644.         default:
  645.           TexOutput("<DL>\n");
  646.           break;
  647.       }
  648.     }
  649.     else
  650.     {
  651.       indentLevel --;
  652.       if (itemizeStack.First())
  653.       {
  654.         ItemizeStruc *struc = (ItemizeStruc *)itemizeStack.First()->Data();
  655.         switch (struc->listType)
  656.         {
  657.           case LATEX_ITEMIZE:
  658.             TexOutput("</UL>\n");
  659.             break;
  660.           case LATEX_ENUMERATE:
  661.             TexOutput("</OL>\n");
  662.             break;
  663.           case LATEX_DESCRIPTION:
  664.           default:
  665.             TexOutput("</DL>\n");
  666.             break;
  667.         }
  668.  
  669.         delete struc;
  670.         delete itemizeStack.First();
  671.       }
  672.     }
  673.     break;
  674.   }
  675.   case ltPAR:
  676.   {
  677.     if (start)
  678.       TexOutput("<P>\n");
  679.     break;
  680.   }
  681.   case ltVERBATIM:
  682.   {
  683.     if (start)
  684.     {
  685.       char buf[100];
  686.       sprintf(buf, "<PRE>\n");
  687.       TexOutput(buf);
  688.     }
  689.     else TexOutput("</PRE>\n");
  690.     break;
  691.   }
  692.   case ltCENTERLINE:
  693.   case ltCENTER:
  694.   {
  695. /*
  696.     if (start)
  697.     {
  698.       TexOutput("{\\qc ");
  699.     }
  700.     else TexOutput("}\\par\\pard\n");
  701. */
  702.     break;
  703.   }
  704.   case ltFLUSHLEFT:
  705.   {
  706. /*
  707.     if (start)
  708.     {
  709.       TexOutput("{\\ql ");
  710.     }
  711.     else TexOutput("}\\par\\pard\n");
  712. */
  713.     break;
  714.   }
  715.   case ltFLUSHRIGHT:
  716.   {
  717. /*
  718.     if (start)
  719.     {
  720.       TexOutput("{\\qr ");
  721.     }
  722.     else TexOutput("}\\par\\pard\n");
  723. */
  724.     break;
  725.   }
  726.   case ltSMALL:
  727.   {
  728. /*
  729.     if (start)
  730.     {
  731.       TexOutput("{\\fs16\n");
  732.     }
  733.     else TexOutput("}\n");
  734. */
  735.     break;
  736.   }
  737.   case ltTINY:
  738.   {
  739. /*
  740.     if (start)
  741.     {
  742.       TexOutput("{\\fs12\n");
  743.     }
  744.     else TexOutput("}\n");
  745. */
  746.     break;
  747.   }
  748.   case ltNORMALSIZE:
  749.   {
  750. /*
  751.     if (start)
  752.     {
  753.       TexOutput("{\\fs20\n");
  754.     }
  755.     else TexOutput("}\n");
  756. */
  757.     break;
  758.   }
  759.   case ltlarge:
  760.   {
  761. /*
  762.     if (start)
  763.     {
  764.       TexOutput("{\\fs24\n");
  765.     }
  766.     else TexOutput("}\n");
  767. */
  768.     break;
  769.   }
  770.   case ltLARGE:
  771.   {
  772.     if (start)
  773.     {
  774.       TexOutput("<H1>");
  775.     }
  776.     else TexOutput("</H1>");
  777.     break;
  778.   }
  779.   case ltLarge:
  780.   {
  781.     if (start)
  782.     {
  783.       TexOutput("<H1>");
  784.     }
  785.     else TexOutput("</H1>");
  786.     break;
  787.   }
  788.   case ltBF:
  789.   {
  790.     if (start)
  791.     {
  792.       TexOutput("<B>");
  793.     }
  794.     else TexOutput("</B>");
  795.     break;
  796.   }
  797.   case ltIT:
  798.   {
  799.     if (start)
  800.     {
  801.       TexOutput("<I>");
  802.     }
  803.     else TexOutput("</I>");
  804.     break;
  805.   }
  806.   case ltEM:
  807.   {
  808.     if (start)
  809.     {
  810.       TexOutput("<EM>");
  811.     }
  812.     else TexOutput("</EM>");
  813.     break;
  814.   }
  815.   case ltUNDERLINE:
  816.   {
  817.     if (start)
  818.     {
  819.       TexOutput("<UL>");
  820.     }
  821.     else TexOutput("</UL>");
  822.     break;
  823.   }
  824.   case ltTT:
  825.   {
  826.     if (start)
  827.     {
  828.       TexOutput("<TT>");
  829.     }
  830.     else TexOutput("</TT>");
  831.     break;
  832.   }
  833. /*
  834.   case ltSC:
  835.   {
  836.     break;
  837.   }
  838. */
  839.   case ltITEM:
  840.   {
  841.     if (!start)
  842.     {
  843.       wxNode *node = itemizeStack.First();
  844.       if (node)
  845.       {
  846.         ItemizeStruc *struc = (ItemizeStruc *)node->Data();
  847.         struc->currentItem += 1;
  848.         if (struc->listType == LATEX_DESCRIPTION)
  849.         {
  850.           if (descriptionItemArg)
  851.           {
  852.             TexOutput("<DT> ");
  853.             TraverseChildrenFromChunk(descriptionItemArg);
  854.             TexOutput("\n");
  855.             descriptionItemArg = NULL;
  856.           }
  857.           TexOutput("<DD>");
  858.         }
  859.         else
  860.           TexOutput("<LI>");
  861.       }
  862.     }
  863.     break;
  864.   }
  865.   case ltMAKETITLE:
  866.   {
  867.     if (start && DocumentTitle && DocumentAuthor)
  868.     {
  869.       // Add a special label for the contents page.
  870.       TexOutput("<A NAME=\"contents\"><HR>");
  871.       TexOutput("<H1>");
  872.       TraverseChildrenFromChunk(DocumentTitle);
  873.       TexOutput("</H1>");
  874.       TexOutput("<HR><P><BR>");
  875.       TexOutput("</A>\n");
  876.       TexOutput("<P>\n\n");
  877.       TexOutput("<H3>");
  878.       TraverseChildrenFromChunk(DocumentAuthor);
  879.       TexOutput("</H3><P>\n\n");
  880.       if (DocumentDate)
  881.       {
  882.         TexOutput("<H3>");
  883.         TraverseChildrenFromChunk(DocumentDate);
  884.         TexOutput("</H3><P>\n\n");
  885.       }
  886.       TexOutput("<P><BR>\n");
  887.     }
  888.     break;
  889.   }
  890.   case ltHELPREF:
  891.   case ltHELPREFN:
  892.   case ltPOPREF:
  893.   {
  894.     if (start)
  895.     {
  896.       helpRefFilename = NULL;
  897.       helpRefText = NULL;
  898.     }
  899.     break;
  900.   }
  901.   case ltBIBLIOGRAPHY:
  902.   {
  903.     if (start)
  904.     {
  905.       DefaultOnMacro(macroId, no_args, start);
  906.     }
  907.     else
  908.     {
  909.       DefaultOnMacro(macroId, no_args, start);
  910.       TexOutput("</DL>\n");
  911.     }
  912.     break;
  913.   }
  914.   case ltHRULE:
  915.   {
  916.     if (start)
  917.     {
  918.       TexOutput("<HR>\n");
  919.     }
  920.     break;
  921.   }
  922.   case ltRULE:
  923.   {
  924.     if (start)
  925.     {
  926.       TexOutput("<HR>\n");
  927.     }
  928.     break;
  929.   }
  930.   case ltTABLEOFCONTENTS:
  931.   {
  932.     if (start)
  933.     {
  934.       FILE *fd = fopen(ContentsName, "r");
  935.       if (fd)
  936.       {
  937.         char ch = getc(fd);
  938.         while (ch != EOF)
  939.         {
  940.           putc(ch, Titlepage);
  941.           ch = getc(fd);
  942.         }
  943.         fclose(fd);
  944.       }
  945.       else
  946.       {
  947.         TexOutput("RUN TEX2RTF AGAIN FOR CONTENTS PAGE\n");
  948.         OnInform("Run Tex2RTF again to include contents page.");
  949.       }
  950.     }
  951.     break;
  952.   }
  953.   case ltLANGLEBRA:
  954.   {
  955.     if (start)
  956.       TexOutput("<");
  957.     break;
  958.   }
  959.   case ltRANGLEBRA:
  960.   {
  961.     if (start)
  962.       TexOutput(">");
  963.     break;
  964.   }
  965.   case ltQUOTE:
  966.   case ltQUOTATION:
  967.   {
  968.     if (start)
  969.       TexOutput("<BLOCKQUOTE>");
  970.     else
  971.       TexOutput("</BLOCKQUOTE>");
  972.     break;
  973.   }
  974.   case ltCAPTION:
  975.   case ltCAPTIONSTAR:
  976.   {
  977.     if (start)
  978.     {
  979.       figureNo ++;
  980.  
  981.       char figBuf[40];
  982.       if (DocumentStyle != LATEX_ARTICLE)
  983.         sprintf(figBuf, "Figure %d.%d: ", chapterNo, figureNo);
  984.       else
  985.         sprintf(figBuf, "Figure %d: ", figureNo);
  986.  
  987.       TexOutput(figBuf);
  988.     }
  989.     else
  990.     {
  991.       char *topicName = FindTopicName(GetNextChunk());
  992.  
  993.       AddTexRef(topicName, NULL, NULL,
  994.            ((DocumentStyle != LATEX_ARTICLE) ? chapterNo : figureNo),
  995.             ((DocumentStyle != LATEX_ARTICLE) ? figureNo : 0));
  996.     }
  997.     break;
  998.   }
  999.   default:
  1000.     DefaultOnMacro(macroId, no_args, start);
  1001.     break;
  1002.   }
  1003. }
  1004.  
  1005. // Called on start/end of argument examination
  1006. Bool HTMLOnArgument(int macroId, int arg_no, Bool start)
  1007. {
  1008.   switch (macroId)
  1009.   {
  1010.   case ltCHAPTER:
  1011.   case ltCHAPTERSTAR:
  1012.   case ltCHAPTERHEADING:
  1013.   case ltSECTION:
  1014.   case ltSECTIONSTAR:
  1015.   case ltSECTIONHEADING:
  1016.   case ltSUBSECTION:
  1017.   case ltSUBSECTIONSTAR:
  1018.   case ltSUBSUBSECTION:
  1019.   case ltSUBSUBSECTIONSTAR:
  1020.   case ltGLOSS:
  1021.   case ltMEMBERSECTION:
  1022.   case ltFUNCTIONSECTION:
  1023.   {
  1024.     if (!start && (arg_no == 1))
  1025.       currentSection = GetArgChunk();
  1026.     return FALSE;
  1027.     break;
  1028.   }
  1029.   case ltFUNC:
  1030.   {
  1031.     if (start && (arg_no == 1))
  1032.       TexOutput("<B>");
  1033.  
  1034.     if (!start && (arg_no == 1))
  1035.       TexOutput("</B> ");
  1036.  
  1037.     if (start && (arg_no == 2))
  1038.     {
  1039.       if (!suppressNameDecoration) TexOutput("<B>");
  1040.       currentMember = GetArgChunk();
  1041.     }
  1042.     if (!start && (arg_no == 2))
  1043.     {
  1044.       if (!suppressNameDecoration) TexOutput("</B>");
  1045.     }
  1046.     
  1047.     if (start && (arg_no == 3))
  1048.       TexOutput("(");
  1049.     if (!start && (arg_no == 3))
  1050.      TexOutput(")");
  1051.    break;
  1052.   }
  1053.   case ltCLIPSFUNC:
  1054.   {
  1055.     if (start && (arg_no == 1))
  1056.       TexOutput("<B>");
  1057.     if (!start && (arg_no == 1))
  1058.       TexOutput("</B> ");
  1059.  
  1060.     if (start && (arg_no == 2))
  1061.     {
  1062.       if (!suppressNameDecoration) TexOutput("( ");
  1063.       currentMember = GetArgChunk();
  1064.     }
  1065.     if (!start && (arg_no == 2))
  1066.     {
  1067.     }
  1068.  
  1069.     if (!start && (arg_no == 3))
  1070.      TexOutput(")");
  1071.     break;
  1072.   }
  1073.   case ltPFUNC:
  1074.   {
  1075.     if (!start && (arg_no == 1))
  1076.       TexOutput(" ");
  1077.  
  1078.     if (start && (arg_no == 2))
  1079.       TexOutput("(*");
  1080.     if (!start && (arg_no == 2))
  1081.       TexOutput(")");
  1082.  
  1083.     if (start && (arg_no == 2))
  1084.       currentMember = GetArgChunk();
  1085.  
  1086.     if (start && (arg_no == 3))
  1087.       TexOutput("(");
  1088.     if (!start && (arg_no == 3))
  1089.       TexOutput(")");
  1090.     break;
  1091.   }
  1092.   case ltPARAM:
  1093.   {
  1094.     if (start && (arg_no == 1))
  1095.       TexOutput("<B>");
  1096.     if (!start && (arg_no == 1))
  1097.       TexOutput("</B>");
  1098.     if (start && (arg_no == 2))
  1099.     {
  1100.       TexOutput("<I>");
  1101.     }
  1102.     if (!start && (arg_no == 2))
  1103.     {
  1104.       TexOutput("</I>");
  1105.     }
  1106.     break;
  1107.   }
  1108.   case ltCPARAM:
  1109.   {
  1110.     if (start && (arg_no == 1))
  1111.       TexOutput("<B>");
  1112.     if (!start && (arg_no == 1))
  1113.       TexOutput("</B> ");  // This is the difference from param - one space!
  1114.     if (start && (arg_no == 2))
  1115.     {
  1116.       TexOutput("<I>");
  1117.     }
  1118.     if (!start && (arg_no == 2))
  1119.     {
  1120.       TexOutput("</I>");
  1121.     }
  1122.     break;
  1123.   }
  1124.   case ltMEMBER:
  1125.   {
  1126.     if (!start && (arg_no == 1))
  1127.       TexOutput(" ");
  1128.  
  1129.     if (start && (arg_no == 2))
  1130.       currentMember = GetArgChunk();
  1131.     break;
  1132.   }
  1133.   case ltREF:
  1134.   {
  1135.     if (start)
  1136.     {
  1137.       char *sec = NULL;
  1138.       
  1139.       char *refName = GetArgData();
  1140.       if (refName)
  1141.       {
  1142.         TexRef *texRef = FindReference(refName);
  1143.         if (texRef)
  1144.         {
  1145.           sec = texRef->sectionNumber;
  1146.         }
  1147.       }
  1148.       if (sec)
  1149.       {
  1150.         TexOutput(sec);
  1151.       }
  1152.       return FALSE;
  1153.     }
  1154.     break;
  1155.   }
  1156.   case ltHELPREF:
  1157.   case ltHELPREFN:
  1158.   case ltPOPREF:
  1159.   {
  1160.     if (IsArgOptional())
  1161.     {
  1162.       if (start)
  1163.         helpRefFilename = GetArgChunk();
  1164.       return FALSE;
  1165.     }
  1166.     else if ((GetNoArgs() - arg_no) == 1)
  1167.     {
  1168.       if (start)
  1169.         helpRefText = GetArgChunk();
  1170.       return FALSE;
  1171.     }
  1172.     else if ((GetNoArgs() - arg_no) == 0) // Arg = 2, or 3 if first is optional
  1173.     {
  1174.       if (start)
  1175.       {
  1176.         char *refName = GetArgData();
  1177.         char *refFilename = NULL;
  1178.  
  1179.         if (refName)
  1180.         {
  1181.           TexRef *texRef = FindReference(refName);
  1182.           if (texRef)
  1183.           {
  1184.             if (texRef->refFile && strcmp(texRef->refFile, "??") != 0)
  1185.               refFilename = texRef->refFile;
  1186.  
  1187.             TexOutput("<A HREF=\"");
  1188.             // If a filename is supplied, use it, otherwise try to
  1189.             // use the filename associated with the reference (from this document).
  1190.             if (helpRefFilename)
  1191.         {
  1192.               TraverseChildrenFromChunk(helpRefFilename);
  1193.               TexOutput("#");
  1194.         }
  1195.             else if (refFilename)
  1196.         {
  1197.               TexOutput(refFilename);
  1198.               TexOutput("#");
  1199.         }
  1200.             TexOutput(refName);
  1201.             TexOutput("\">");
  1202.             if (helpRefText)
  1203.               TraverseChildrenFromChunk(helpRefText);
  1204.             TexOutput("</A>");
  1205.           }
  1206.         }
  1207.         else TexOutput("??");
  1208.       }
  1209.       return FALSE;
  1210.     }
  1211.     break;
  1212.   }
  1213.   case ltIMAGE:
  1214.   case ltPSBOXTO:
  1215.   {
  1216.     if (arg_no == 2)
  1217.     {
  1218.       if (start)
  1219.       {
  1220.         // Try to find an XBM or GIF image first.
  1221.         char *filename = copystring(GetArgData());
  1222.         char buf[500];
  1223.         
  1224.         strcpy(buf, filename);
  1225.         StripExtension(buf);
  1226.         strcat(buf, ".xbm");
  1227.         char *f = TexPathList.FindValidPath(buf);
  1228.  
  1229.         if (!f) // Try for a GIF instead
  1230.         {
  1231.           strcpy(buf, filename);
  1232.           StripExtension(buf);
  1233.           strcat(buf, ".gif");
  1234.           f = TexPathList.FindValidPath(buf);
  1235.         }
  1236.         if (f)
  1237.         {
  1238.           char *inlineFilename = copystring(f);
  1239.           char *originalFilename = TexPathList.FindValidPath(filename);
  1240.           
  1241.           // If we have found the existing filename, make the inline
  1242.           // image point to the original file (could be PS, for example)
  1243.           if (originalFilename)
  1244.       {
  1245.             TexOutput("<A HREF=\"");
  1246.             TexOutput(originalFilename);
  1247.             TexOutput("\">");
  1248.             TexOutput("<img align=top src=\"");
  1249.             TexOutput(inlineFilename);
  1250.             TexOutput("\"></A><P>");
  1251.             delete[] originalFilename;
  1252.       }
  1253.           else
  1254.       {
  1255.             TexOutput("<img align=top src=\"");
  1256.             TexOutput(inlineFilename);
  1257.             TexOutput("\"><P>");
  1258.       }
  1259.         }
  1260.         else
  1261.         {
  1262.           // Last resort - a link to a PS file.
  1263.           TexOutput("<A HREF=\"");
  1264.           TexOutput(filename);
  1265.           TexOutput("\">Picture</A><P>\n");
  1266.           sprintf(buf, "Warning: could not find an inline XBM/GIF for %s.", filename);
  1267.           OnInform(buf);
  1268.         }
  1269.       }
  1270.     }
  1271.     return FALSE;
  1272.     break;
  1273.   }
  1274.   case ltITEM:
  1275.   {
  1276.     if (start)
  1277.     {
  1278.       descriptionItemArg = GetArgChunk();
  1279.       return FALSE;
  1280.     }
  1281.   }
  1282.   case ltTWOCOLITEM:
  1283.   case ltTWOCOLITEMRULED:
  1284.   {
  1285.     if (start && (arg_no == 1))
  1286.       TexOutput("\n<DT> ");
  1287.     if (start && (arg_no == 2))
  1288.       TexOutput("<DD> ");
  1289.     return TRUE;
  1290.     break;
  1291.   }
  1292.   case ltNUMBEREDBIBITEM:
  1293.   {
  1294.     if (arg_no == 1 && start)
  1295.     {
  1296.       TexOutput("\n<DT> ");
  1297.     }
  1298.     if (arg_no == 2 && !start)
  1299.       TexOutput("<P>\n");
  1300.     break;
  1301.   }
  1302.   case ltBIBITEM:
  1303.   {
  1304.     char buf[100];
  1305.     if (arg_no == 1 && start)
  1306.     {
  1307.       char *citeKey = GetArgData();
  1308.       TexRef *ref = (TexRef *)TexReferences.Get(citeKey);
  1309.       if (ref)
  1310.       {
  1311.         if (ref->sectionNumber) delete[] ref->sectionNumber;
  1312.         sprintf(buf, "[%d]", citeCount);
  1313.         ref->sectionNumber = copystring(buf);
  1314.       }
  1315.  
  1316.       sprintf(buf, "\n<DT> [%d] ", citeCount);
  1317.       TexOutput(buf);
  1318.       citeCount ++;
  1319.       return FALSE;
  1320.     }
  1321.     if (arg_no == 2 && !start)
  1322.       TexOutput("<P>\n");
  1323.     return TRUE;
  1324.     break;
  1325.   }
  1326.   case ltMARGINPAR:
  1327.   case ltMARGINPARODD:
  1328.   case ltMARGINPAREVEN:
  1329.   case ltNORMALBOX:
  1330.   case ltNORMALBOXD:
  1331.   {
  1332.     if (start)
  1333.     {
  1334.       TexOutput("<HR>\n");
  1335.       return TRUE;
  1336.     }
  1337.     else
  1338.       TexOutput("<HR><P>\n");
  1339.     break;
  1340.   }
  1341.   /*
  1342.    * Accents
  1343.    *
  1344.    */
  1345.   case ltACCENT_GRAVE:
  1346.   {
  1347.     if (start)
  1348.     {
  1349.       char *val = GetArgData();
  1350.       if (val)
  1351.       {
  1352.         switch (val[0])
  1353.         {
  1354.           case 'a':
  1355.            TexOutput("à");
  1356.            break;
  1357.           case 'e':
  1358.            TexOutput("è");
  1359.            break;
  1360.           case 'i':
  1361.            TexOutput("ì");
  1362.            break;
  1363.           case 'o':
  1364.            TexOutput("ò");
  1365.            break;
  1366.           case 'u':
  1367.            TexOutput("ù");
  1368.            break;
  1369.           case 'A':
  1370.            TexOutput("À");
  1371.            break;
  1372.           case 'E':
  1373.            TexOutput("È");
  1374.            break;
  1375.           case 'I':
  1376.            TexOutput("Ì");
  1377.            break;
  1378.           case 'O':
  1379.            TexOutput("Ò");
  1380.            break;
  1381.           case 'U':
  1382.            TexOutput("Ì");
  1383.            break;
  1384.           default:
  1385.            break;
  1386.         }
  1387.       }
  1388.     }
  1389.     return FALSE;
  1390.     break;
  1391.   }
  1392.   case ltACCENT_ACUTE:
  1393.   {
  1394.     if (start)
  1395.     {
  1396.       char *val = GetArgData();
  1397.       if (val)
  1398.       {
  1399.         switch (val[0])
  1400.         {
  1401.           case 'a':
  1402.            TexOutput("á");
  1403.            break;
  1404.           case 'e':
  1405.            TexOutput("é");
  1406.            break;
  1407.           case 'i':
  1408.            TexOutput("í");
  1409.            break;
  1410.           case 'o':
  1411.            TexOutput("ó");
  1412.            break;
  1413.           case 'u':
  1414.            TexOutput("ú");
  1415.            break;
  1416.           case 'y':
  1417.            TexOutput("ý");
  1418.            break;
  1419.           case 'A':
  1420.            TexOutput("Á");
  1421.            break;
  1422.           case 'E':
  1423.            TexOutput("É");
  1424.            break;
  1425.           case 'I':
  1426.            TexOutput("Í");
  1427.            break;
  1428.           case 'O':
  1429.            TexOutput("Ó");
  1430.            break;
  1431.           case 'U':
  1432.            TexOutput("Ú");
  1433.            break;
  1434.           case 'Y':
  1435.            TexOutput("Ý");
  1436.            break;
  1437.           default:
  1438.            break;
  1439.         }
  1440.       }
  1441.     }
  1442.     return FALSE;
  1443.     break;
  1444.   }
  1445.   case ltACCENT_CARET:
  1446.   {
  1447.     if (start)
  1448.     {
  1449.       char *val = GetArgData();
  1450.       if (val)
  1451.       {
  1452.         switch (val[0])
  1453.         {
  1454.           case 'a':
  1455.            TexOutput("â");
  1456.            break;
  1457.           case 'e':
  1458.            TexOutput("ê");
  1459.            break;
  1460.           case 'i':
  1461.            TexOutput("î");
  1462.            break;
  1463.           case 'o':
  1464.            TexOutput("ô");
  1465.            break;
  1466.           case 'u':
  1467.            TexOutput("û");
  1468.            break;
  1469.           case 'A':
  1470.            TexOutput("Â");
  1471.            break;
  1472.           case 'E':
  1473.            TexOutput("Ê");
  1474.            break;
  1475.           case 'I':
  1476.            TexOutput("Î");
  1477.            break;
  1478.           case 'O':
  1479.            TexOutput("Ô");
  1480.            break;
  1481.           case 'U':
  1482.            TexOutput("Î");
  1483.            break;
  1484.           default:
  1485.            break;
  1486.         }
  1487.       }
  1488.     }
  1489.     return FALSE;
  1490.     break;
  1491.   }
  1492.   case ltACCENT_TILDE:
  1493.   {
  1494.     if (start)
  1495.     {
  1496.       char *val = GetArgData();
  1497.       if (val)
  1498.       {
  1499.         switch (val[0])
  1500.         {
  1501.           case 'a':
  1502.            TexOutput("ã");
  1503.            break;
  1504.           case 'n':
  1505.            TexOutput("ñ");
  1506.            break;
  1507.           case 'o':
  1508.            TexOutput("õ");
  1509.            break;
  1510.           case 'A':
  1511.            TexOutput("Ã");
  1512.            break;
  1513.           case 'N':
  1514.            TexOutput("Ñ");
  1515.            break;
  1516.           case 'O':
  1517.            TexOutput("Õ");
  1518.            break;
  1519.           default:
  1520.            break;
  1521.         }
  1522.       }
  1523.     }
  1524.     return FALSE;
  1525.     break;
  1526.   }
  1527.   case ltACCENT_UMLAUT:
  1528.   {
  1529.     if (start)
  1530.     {
  1531.       char *val = GetArgData();
  1532.       if (val)
  1533.       {
  1534.         switch (val[0])
  1535.         {
  1536.           case 'a':
  1537.            TexOutput("ä");
  1538.            break;
  1539.           case 'e':
  1540.            TexOutput("ë");
  1541.            break;
  1542.           case 'i':
  1543.            TexOutput("ï");
  1544.            break;
  1545.           case 'o':
  1546.            TexOutput("ö");
  1547.            break;
  1548.           case 'u':
  1549.            TexOutput("ü");
  1550.            break;
  1551.           case 'y':
  1552.            TexOutput("ÿ");
  1553.            break;
  1554.           case 'A':
  1555.            TexOutput("Ä");
  1556.            break;
  1557.           case 'E':
  1558.            TexOutput("Ë");
  1559.            break;
  1560.           case 'I':
  1561.            TexOutput("Ï");
  1562.            break;
  1563.           case 'O':
  1564.            TexOutput("Ö");
  1565.            break;
  1566.           case 'U':
  1567.            TexOutput("Ü");
  1568.            break;
  1569.           case 'Y':
  1570.            TexOutput("Ÿ");
  1571.            break;
  1572.           default:
  1573.            break;
  1574.         }
  1575.       }
  1576.     }
  1577.     return FALSE;
  1578.     break;
  1579.   }
  1580.   case ltACCENT_DOT:
  1581.   {
  1582.     if (start)
  1583.     {
  1584.       char *val = GetArgData();
  1585.       if (val)
  1586.       {
  1587.         switch (val[0])
  1588.         {
  1589.           case 'a':
  1590.            TexOutput("å");
  1591.            break;
  1592.           case 'A':
  1593.            TexOutput("Å");
  1594.            break;
  1595.           default:
  1596.            break;
  1597.         }
  1598.       }
  1599.     }
  1600.     return FALSE;
  1601.     break;
  1602.   }
  1603.   case ltACCENT_CADILLA:
  1604.   {
  1605.     if (start)
  1606.     {
  1607.       char *val = GetArgData();
  1608.       if (val)
  1609.       {
  1610.         switch (val[0])
  1611.         {
  1612.           case 'c':
  1613.            TexOutput("ç");
  1614.            break;
  1615.           case 'C':
  1616.            TexOutput("Ç");
  1617.            break;
  1618.           default:
  1619.            break;
  1620.         }
  1621.       }
  1622.     }
  1623.     return FALSE;
  1624.     break;
  1625.   }
  1626.   case ltTHEBIBLIOGRAPHY:
  1627.   {
  1628.     if (start && (arg_no == 1))
  1629.     {
  1630.       ReopenFile(&Chapters, &ChaptersName);
  1631.       AddTexRef("bibliography", ChaptersName, "bibliography");
  1632.       SetCurrentSubsectionName("bibliography", ChaptersName);
  1633.  
  1634.       citeCount = 1;
  1635.  
  1636.       SetCurrentOutput(Chapters);
  1637.       fprintf(Chapters, "<A NAME=\"%s\">\n<H2>%s", "bibliography", ReferencesNameString);
  1638.  
  1639.       char titleBuf[100];
  1640.       sprintf(titleBuf, "%s_contents.html", FileNameFromPath(FileRoot));
  1641.       AddBrowseButtons("contents", titleBuf, // Up
  1642.                        lastTopic, lastFileName,  // Last topic
  1643.                        "bibliography", ChaptersName); // This topic
  1644.  
  1645.       TexOutput("<title>");
  1646.       TexOutput(ReferencesNameString);
  1647.       TexOutput("</title>\n");
  1648.  
  1649.       SetCurrentOutputs(Contents, Chapters);
  1650.       fprintf(Contents, "\n<LI><A HREF=\"%s#%s\">", ChaptersName, "bibliography");
  1651.  
  1652.       fprintf(Contents, "%s</A>\n", ReferencesNameString);
  1653.       fprintf(Chapters, "</H2>\n</A>\n");
  1654.  
  1655.       SetCurrentOutput(Chapters);
  1656.       return FALSE;
  1657.     }
  1658.     if (!start && (arg_no == 2))
  1659.     {
  1660.     }
  1661.     return TRUE;
  1662.     break;
  1663.   }
  1664.   default:
  1665.     return DefaultOnArgument(macroId, arg_no, start);
  1666.     break;
  1667.   }
  1668.   return TRUE;
  1669. }
  1670.  
  1671. Bool HTMLGo(void)
  1672. {
  1673.   fileId = 0;
  1674.   inVerbatim = FALSE;
  1675.   indentLevel = 0;
  1676.  
  1677.   if (InputFile && OutputFile)
  1678.   {
  1679.     // Do some HTML-specific transformations on all the strings,
  1680.     // recursively
  1681.     Text2HTML(GetTopLevelChunk());
  1682.  
  1683.     char buf[300];
  1684.     sprintf(buf, "%s_contents.html", FileRoot);
  1685.     if (TitlepageName) delete[] TitlepageName;
  1686.     TitlepageName = copystring(buf);
  1687.     Titlepage = fopen(buf, "w");
  1688.  
  1689.     Contents = fopen(TmpContentsName, "w");
  1690.     if (!Titlepage || !Contents)
  1691.     {
  1692.       OnError("Cannot open output file!");
  1693.       return FALSE;
  1694.     }
  1695.     AddTexRef("contents", FileNameFromPath(TitlepageName), ContentsNameString);
  1696.  
  1697.     fprintf(Contents, "<P><P><H1>%s</H1><P><P>\n", ContentsNameString);
  1698.  
  1699.     fprintf(Contents, "<UL>\n");
  1700.  
  1701.     SetCurrentOutput(Titlepage);
  1702.     OnInform("Converting...");
  1703.  
  1704.     TraverseDocument();
  1705.  
  1706.     if (DocumentTitle)
  1707.     {
  1708.       SetCurrentOutput(Titlepage);
  1709.       TexOutput("\n<TITLE>");
  1710.       TraverseChildrenFromChunk(DocumentTitle);
  1711.       TexOutput("</TITLE>\n");
  1712.     }
  1713.     else
  1714.     {
  1715.       if (contentsString)
  1716.         fprintf(Titlepage, "<TITLE>%s</TITLE>\n\n", contentsString);
  1717.       else
  1718.         fprintf(Titlepage, "<TITLE>%s</TITLE>\n\n", FileNameFromPath(FileRoot));
  1719.     }
  1720.  
  1721.     fprintf(Contents, "</UL>\n\n");
  1722.     if (Titlepage)
  1723.       fclose(Titlepage);
  1724.     if (Contents)
  1725.       fclose(Contents);
  1726.     if (Chapters)
  1727.       fclose(Chapters);
  1728.     if (Sections)
  1729.       fclose(Sections);
  1730.     if (Subsections)
  1731.       fclose(Subsections);
  1732.     if (Subsubsections)
  1733.       fclose(Subsubsections);
  1734.  
  1735.     if (lastFileName) delete[] lastFileName;
  1736.     lastFileName = NULL;
  1737.     if (lastTopic) delete[] lastTopic;
  1738.     lastTopic = NULL;
  1739.  
  1740.     if (FileExists(ContentsName)) wxRemoveFile(ContentsName);
  1741.     wxRenameFile(TmpContentsName, ContentsName);
  1742.  
  1743.     return TRUE;
  1744.   }
  1745.   return FALSE;
  1746. }
  1747.  
  1748.